package com.xinshujia.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xinshujia.entity.ResourceEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Set;

/**
 * *************************************
 * *   @author: 野狼上校               **
 * *   @since: 2024-07-12 09:25       **
 * *   @version: 1.0                  **
 * *************************************
 * <p>
 *     资源持久化
 *     基本查询和分页查询
 */
@Mapper
public interface ResourceDao extends BaseMapper<ResourceEntity>{
    /**
     * 根据角色ids查询资源
     * @param roleIds 角色id
     * @return 资源
     */
    @Select("<script>" +
            "SELECT DISTINCT r.* FROM auth_resource r, auth_role_resource rr WHERE r.id = rr.resource_id AND rr.role_id IN " +
            "<foreach collection='roleIds' item='roleId' open='(' separator=',' close=')'>" +
            "#{roleId}" +
            "</foreach>" +
            "</script>")
    Set<ResourceEntity> findResourcesByRIds(@Param("roleIds") Set<Long> roleIds);
}